
#include "StdAfx.h"
#include "CDMChannel.h"
#include "CDMDevice.h"
#include "MonitorPlatform.h"

CCDMChannel::CCDMChannel(CHANNEL_INFO* pDBChannelInfo, PowerInfo* pInfo, CDevice* pDevice)
			:CChannel(pDBChannelInfo, pInfo, pDevice)
			, m_pRecDownloadProc(NULL)
			, m_pUserData(NULL)
{
	
}

CCDMChannel::~CCDMChannel(void)
{
}

DWORD CCDMChannel::GetStreamTransmitCaps(STREAM_TYPE StreamType)
{
	DWORD dwCaps = 0;
	switch(StreamType)
	{
	case REMOTE_RECORD_STREAM:
		dwCaps = (TRANS_CAPS_FAST_FORWARD|TRANS_CAPS_SLOW_FORWARD|TRANS_CAPS_FRAME_FORWARD);
		break;
	case LOCAL_RECORD_STREAM:
		dwCaps = (TRANS_CAPS_FAST_FORWARD|TRANS_CAPS_SLOW_FORWARD|TRANS_CAPS_FRAME_FORWARD|TRANS_CAPS_FRAME_REVERSE);
		break;
	}

	return dwCaps;
}

void CCDMChannel::SetChannelPermit(int nCMDPermit, int nChannelNO)
{
	DWORD dwPermit = 0;

	if(nCMDPermit & CDM_CP_PLAY_VIDEO)
		dwPermit |= (CP_PLAY_REALTIME_VIDEO|CP_PLAY_RECORD_VIDEO);

	if(nCMDPermit & CDM_CP_OPERATE_PTZ)
		dwPermit |= CP_OPERATE_PTZ;

	if(nCMDPermit & CDM_CP_SET_PREPOSITION)
		dwPermit |= CP_SET_PREPOSITION;

	if(nCMDPermit & CDM_CP_TALKBACK)
		dwPermit |= CP_TALKBACK;

	if(nCMDPermit & CDM_CP_IMAGE_ADJUST)
		dwPermit |= CP_IMAGE_ADJUST;

	if(nCMDPermit & CDM_CP_CONTROL_RECORD)
		dwPermit |= CP_CONTROL_RECORD;

	if(nCMDPermit & CDM_CP_SET_CAMERA_PARAM)
		dwPermit |= CP_SET_CAMERA_PARAM;

	CChannel::SetChannelPermit(dwPermit);
}

BOOL CCDMChannel::DownloadRecordFile(LPCTSTR lpszRemoteFileName, LPCTSTR lpszLocalFileName, RECORD_DOWNLOAD_PROC pRecDownloadProc, void *pUserData)
{
	CIpcdmclient* pCDMClientOcxCtrl = thePlatform.GetCDMClientOcxCtrl();

	m_pRecDownloadProc = pRecDownloadProc;
	m_pUserData = pUserData;

	return (thePlatform.DownloadRecordFile(this, lpszRemoteFileName, lpszLocalFileName));
}

void CCDMChannel::CallRecordDownloadProc(int nProgress, DWORD dwError, DWORD* pCtrl)
{
	if(m_pRecDownloadProc)
	{
		m_pRecDownloadProc(m_pUserData, nProgress, dwError, pCtrl);
	}
}